package javashiyanbaogao;

class MemberCard {
    protected String cardType;
    protected double balance;

    public MemberCard(String cardType, double balance) {
        this.cardType = cardType;
        this.balance = balance;
    }

    public double pay(double amount) {
        return amount;
    }
}

class NormalCard extends MemberCard {
    public NormalCard(double balance) {
        super("一般会员卡", balance);
    }

    @Override
    public double pay(double amount) {
        return amount * 0.9; // 9折
    }
}

class VipCard extends MemberCard {
    public VipCard(double balance) {
        super("VIP会员卡", balance);
    }

    @Override
    public double pay(double amount) {
        return amount * 0.7; // 7折
    }
}

class SuperVipCard extends MemberCard {
    public SuperVipCard(double balance) {
        super("超级VIP会员卡", balance);
    }

    @Override
    public double pay(double amount) {
        return amount * 0.5; // 5折
    }
}

class CardMachine {
    public void consume(MemberCard card, double amount) {
        if (card.balance < amount) {
            System.out.println("余额不足，无法完成交易！");
            return;
        }
        double actualAmount = card.pay(amount);
        card.balance -= actualAmount;
        System.out.println("消费成功！卡类型：" + card.cardType);
        System.out.println("原价：" + amount + "元，实际应付："
                + actualAmount + "元");
        System.out.println("卡内余额：" + card.balance + "元");
    }
}

public class duotai {
    public static void main(String[] args) {
        MemberCard normalCard = new NormalCard(1000.0);
        MemberCard vipCard = new VipCard(1000.0);
        MemberCard superVipCard = new SuperVipCard(1000.0);

        CardMachine machine = new CardMachine();

        double amountToPay = 987.0;

        System.out.println("使用一般会员卡消费：");
        machine.consume(normalCard, amountToPay);

        System.out.println("\n使用VIP会员卡消费：");
        machine.consume(vipCard, amountToPay);

        System.out.println("\n使用超级VIP会员卡消费：");
        machine.consume(superVipCard, amountToPay);
    }
}
